Undefined behavior of computer software may be exploited by attackers to execute arbitrary code, gain privileges, and commit other acts. An example of this is return-oriented programming (ROP), where an attacker uses a bug in the software to cause buffer overflows of data. The attacker then constructs a number of “gadgets” from existing code whose addresses are chained together on the stack. When a return instruction is repeatedly called, the gadgets are executed. This type of operation where existing code is chained together and driven with buffer overflow is sometimes called a “weird machine.” A simple software bug may thus become a serious security vulnerability. The present disclosure relates to techniques for dealing with this problem.